package com.example.barcodeapp.ui.huodong;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.ui.own.bean.HuoDongBean;

import java.util.List;

public class AdapterLeiBiao extends RecyclerView.Adapter<AdapterLeiBiao.ViewHolder> {
    Context context;
    private List<HuoDongBean.DataEntity> list;

    public AdapterLeiBiao(Context context, List<HuoDongBean.DataEntity> list) {
        this.context = context;
        this.list = list;
    }
    private AdapterLeiBiao.IClick callback;

    public void setCallback(IClick callback) {
        this.callback = callback;
    }

    public AdapterLeiBiao(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_huoodong_leibiao, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(context).load(Constants.Base_TPUrl2 +list.get(position).getHuodong_image()).into( holder.leibiaoImg);
        holder.leibiaoTvName.setText(list.get(position).getHuodong_name());
        holder.leibiaoTvNeirong.setText(list.get(position).getHuodong_date_desc());
        holder.leibiaoTvNeirong.setText(list.get(position).getHuodong_date_desc());
        holder.jiage.setText(list.get(position).getHuodong_price()+"￥");

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.click(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView leibiaoImg;
        private ImageView imageView2;
        private TextView leibiaoTvName;
        private TextView leibiaoTvNeirong;
        private TextView jiage;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            leibiaoImg = (ImageView) itemView.findViewById(R.id.leibiao_img);
            imageView2 = (ImageView) itemView.findViewById(R.id.imageView2);
            leibiaoTvName = (TextView) itemView.findViewById(R.id.leibiao_tv_name);
            leibiaoTvNeirong = (TextView) itemView.findViewById(R.id.leibiao_tv_neirong);
            jiage = (TextView) itemView.findViewById(R.id.jiage);
        }
    }
    public interface IClick{
        void click(int pos);
    }
}
